home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SOUND.SWG / 0036_DETECTS SoundBlaster.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  3KB  |  124 lines

  1. {
  2. From: LENNERT BAKKER
  3. Subj: SB AutoDetect
  4.     Here's how to autodetect a soundblaster and it's baseaddress
  5.     and some other support-stuff for your convenience: }
  6.  
  7.  
  8. { Hey let's check this SB out 8-)}
  9.  
  10. Const SBReset     = $6;
  11.       SBRead      = $A;
  12.       SBWrite     = $C;
  13.       SBStatus    = $E;
  14.  
  15. Var   SBPort      : Word;
  16.       SBInstalled : Boolean;
  17.  
  18. Procedure DetectSoundBlaster;
  19. Const NrTimes           = 10;
  20.       NrTimes2          = 50;
  21. Var   Found             : Boolean;
  22.       Counter1,Counter2 : Word;
  23. Begin
  24.  SBPort:=$210;
  25.  Found:=False;
  26.  Counter1:=NrTimes;
  27.   While (SBPort<=$260) And Not Found Do
  28.    Begin
  29.     Port[SBPort+$6]:=1;
  30.     Port[SBPort+$6]:=0;
  31.     Counter2:=NrTimes2;
  32.      While (Counter2>0) And (Port[SBPort+$E]<128) Do
  33.       Dec(Counter2);
  34.      If (Counter2=0) Or (Port[SBPort+$A]<>$AA) Then
  35.       Begin
  36.        Dec(Counter1);
  37.         If (Counter1=0) Then
  38.          Begin
  39.           Counter1:=NrTimes;
  40.           SBPort:=SBPort+$10;
  41.          End
  42.       End Else Found:=True;
  43.    End;
  44.   If Found then SBInstalled:=True
  45.    Else SBInstalled:=False;
  46. End;
  47.  
  48. Begin
  49.  DetectSoundBlaster;
  50.   If SBInstalled then
  51.    Writeln('SoundBlaster found at port :', SBPort)
  52.   else
  53.    Writeln('No soundcard, no boogie!');
  54. End.
  55.  
  56.  
  57. {Here's how to initialize the DSP:}
  58.  
  59. Procedure SetupSoundBlaster;
  60. Var I,BDum : Byte;
  61. Begin
  62.   If SBInstalled then
  63.    Begin
  64.     Port[SBPort+SBReset]:=1; {Reset DSP}
  65.      For I:=1 to 6 do
  66.       BDum:=Port[SBPort+SBStatus];
  67.     Port[SBPort+SBReset]:=0;
  68.      For I:=1 to 6 do
  69.       BDum:=Port[SBPort+SBStatus];
  70.      Repeat Until Port[SBPort+SBStatus]>$80;
  71.    End;
  72. End;
  73.  
  74. {Respectively turn the speaker on/off}
  75.  
  76. Procedure TurnOnSBSpeaker;
  77. Begin
  78.  Repeat Until Port[SBPort+SBWrite]<$80;
  79.  Port[SBPort+SBWrite]:=$D1;
  80. End;
  81.  
  82. Procedure TurnOffSBSpeaker;
  83. Begin
  84.  Repeat Until Port[SBPort+SBWrite]<$80;
  85.  Port[SBPort+SBWrite]:=$D3;
  86. End;
  87.  
  88. {
  89.   Here's basically how you play a sample, you should reprogram
  90.   the timer though and have your interrupt routine output bytes
  91.   to the DSP at regular intervals, say 10000 times/sec or so.
  92.   Rather use machine-language instead, but that shouldn't be too
  93.   hard now, should it? 8)
  94. }
  95.  
  96. Procedure PlaySample(Sample:Pointer;Length:Word);
  97. Var A : Word;
  98. Begin
  99.  For A:=1 to Length Do
  100.   Begin
  101.    Port[SBPort+SBWrite]:=$10;
  102.    Port[SBPort+SBWrite]:=Mem[Seg(Sample^):Ofs(Sample^)+A];
  103.    {Delay some time}
  104.   End;
  105. End;
  106.  
  107. {Or sumtin like this (untested) }
  108.  
  109. Procedure PlaySampleASM(Sample:Pointer;Length:Word); Assembler;
  110. Asm
  111.  Les Di,[Sample]
  112.  Mov Dx,SBPort+SBWrite
  113.  Mov Cx,Length
  114. @LoopIt:
  115.  LodsB
  116.  Out Dx,$10
  117.  Out Dx,Al
  118.  
  119.  { Delay Some Time -- What about 1000 NOPs or so ;-) }
  120.  
  121.  Loop @LoopIt
  122. End;
  123.  
  124.